﻿@using Abp.Collections.Extensions
@using Snow.Template.Web.Views
@using Snow.Template.Web.Views.Shared.Components.SideBarNav
@model SideBarNavViewModel
@{
    int i = 1;
    string className;
    var calculateMenuUrl = new Func<string, string>((url) =>
    {
        if (string.IsNullOrEmpty(url))
        {
            return ApplicationPath;
        }

        if (UrlChecker.IsRooted(url))
        {
            return url;
        }

        return ApplicationPath + url;
    });
}

<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">

    @foreach (var menuItem in Model.MainMenu.Items)
    {
        if (menuItem.Items.IsNullOrEmpty())
        {
            <li class="nav-item">
                <a href="@calculateMenuUrl(menuItem.Url)" class="nav-link">
                    <i class="nav-icon @menuItem.Icon"></i>
                    <p>
                        @menuItem.Name
                    </p>
                </a>
            </li>
        }
        else
        {
            className = "nav-item has-treeview";
            if (i == 1)
            {
                className += " menu-open";
            }
            <li class="@className">
                <a href="#" class="nav-link">
                    <i class="nav-icon @menuItem.Icon"></i>
                    <p>
                        @menuItem.Name
                        <i class="right fas fa-chevron-down"></i>
                    </p>
                </a>
                <ul class="nav nav-treeview">
                    @foreach (var subMenuItem in menuItem.Items)
                    {
                        <li class="nav-item">
                            <a href="javascript:void(0);" data-href="@calculateMenuUrl(subMenuItem.Url)" class="nav-link deepNav" data-name="@subMenuItem.Name" data-id="@subMenuItem.Target.Substring(subMenuItem.Target.IndexOf('_') + 1)" target="@subMenuItem.Target">
                                <i class="far fa-circle nav-icon"></i>
                                <p>@subMenuItem.Name</p>
                            </a>
                        </li>
                        i++;
                    }
                </ul>
            </li>
        }
    }
</ul>
+
@*<div class="menu">
        <ul class="list">
            @foreach (var menuItem in Model.MainMenu.Items)
            {
                <li class="@(Model.ActiveMenuItemName == menuItem.Name ? "active" : "")">
                    @if (menuItem.Items.IsNullOrEmpty())
                    {
                        <a href="@calculateMenuUrl(menuItem.Url)">
                            @if (!string.IsNullOrWhiteSpace(menuItem.Icon))
                            {
                                <i class="material-icons">@menuItem.Icon</i>
                            }
                            <span>@menuItem.DisplayName</span>
                        </a>
                    }
                    else
                    {
                        <a href="javascript:void(0);" class="menu-toggle">
                            @if (!string.IsNullOrWhiteSpace(menuItem.Icon))
                            {
                                <i class="material-icons">@menuItem.Icon</i>
                            }
                            <span>@menuItem.DisplayName</span>
                        </a>
                        <ul class="ml-menu">
                            @foreach (var subMenuItem in menuItem.Items)
                            {
                                <li class="@(Model.ActiveMenuItemName == subMenuItem.Name ? "active" : "")">
                                    @if (subMenuItem.Items.IsNullOrEmpty())
                                    {
                                        <a href="@calculateMenuUrl(subMenuItem.Url)">
                                            @if (!string.IsNullOrWhiteSpace(subMenuItem.Icon))
                                            {
                                                <i class="material-icons">@subMenuItem.Icon</i>
                                            }
                                            <span>@subMenuItem.DisplayName</span>
                                        </a>
                                    }
                                    else
                                    {
                                        <a href="javascript:void(0);" class="menu-toggle">
                                            @if (!string.IsNullOrWhiteSpace(subMenuItem.Icon))
                                            {
                                                <i class="material-icons">@subMenuItem.Icon</i>
                                            }
                                            <span>@subMenuItem.DisplayName</span>
                                        </a>
                                        <ul class="ml-menu">
                                            @foreach (var subSubMenuItem in subMenuItem.Items)
                                            {
                                                <li class="@(Model.ActiveMenuItemName == subSubMenuItem.Name ? "active" : "")">
                                                    <a href="@calculateMenuUrl(subSubMenuItem.Url)">
                                                        @subSubMenuItem.DisplayName
                                                    </a>
                                                </li>
                                            }
                                        </ul>
                                    }
                                </li>
                            }
                        </ul>
                    }
                </li>
            }
        </ul>
    </div>*@